package com.zhu.utils;

import java.io.*;

/**
 * @ClassName CopyUtils
 * @Description TODO
 * @Author zhuxiongbin
 * @Date 2021-11-04 14:48
 * @Version 1.0.0
 */
public class CopyUtils {

    public static <T> T deepClone(T src) {

        Object obj = null;
        try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
             ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream)) {
            objectOutputStream.writeObject(src);
            try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
                 ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream)) {
                obj = objectInputStream.readObject();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return (T) obj;
    }

    public static void main(String[] args) {
        //Object objNew = CopyUtils.deepClone(objOld);
    }

}
